#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

const int mod = 1e9 + 7;

struct Task {
    int idx;
    double a;
    double b;
};

bool cmp(const Task& x, const Task& y) {
    double v1 = x.a * (1.0 + y.b);
    double v2 = y.a * (1.0 + x.b);
    if (fabs(v1 - v2) < 1e-9) {
        return x.idx < y.idx;
    }
    return v1 < v2;
}

int main() {
    int n;
    cin >> n;
    vector<Task> tasks(n);
    for (int i = 0; i < n; i++) {
        cin >> tasks[i].a >> tasks[i].b;
        tasks[i].idx = i;
    }

    sort(tasks.begin(), tasks.end(), cmp);
    
    int prev = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        prev = (prev + (int)tasks[i].a + prev * (int)tasks[i].b) % mod;
        sum = (sum + prev) % mod;
    }
    cout << sum << endl;
    return 0;
}